package gui;

import java.util.ArrayList;

import javax.swing.JPanel;

import model.Location;
import dao.Dao;

public class StockPanel extends JPanel implements Updatable {

    private int width;
    private int height;

    private ArrayList<StackPanel> stackList = new ArrayList<StackPanel>();

    public StockPanel(int width, int height) {
	setLayout(null);
	this.width = width;
	this.height = height;
	setSize(600, 500);
	setLocation(10, 10);

	ArrayList<Location> locations = Dao.getInstance().getLocations();
	for (int i = 0; i < height; i++) {
	    for (int j = 0; j < width; j++) {
		StackPanel pnl = new StackPanel(locations.get(i * height + j));
		add(pnl);
		pnl.setLocation(getWidth() / width * j + 5, getHeight()
			/ height * i + 10);
		stackList.add(pnl);
	    }
	}

    }

    public void updateView() {

	for (StackPanel sp : stackList) {
	    sp.updateView();
	}
    }
}
